package com.haoze.nurseapp.enumeration;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author embed
 */
public class WorkSpaceEnum {

    private String enumValue;
    private String enumName;
    private String nodeId;
    private String nodeKey;
    public final static Map<String, WorkSpaceEnum> ENUM_MAP = new HashMap();

    /**
     * 静配收药
     */
    public final static WorkSpaceEnum STATIC_DRUG_COLLECTION = new WorkSpaceEnum("1", "静配收药", "787382c114f54aabb20696ce135f5fb6","staticDrug");
    /**
     * 非静配收药
     */
    public final static WorkSpaceEnum UNSTATIC_DRUG_COLLECTION = new WorkSpaceEnum("2", "非静配收药", "", "unStaticDrug");
    /**
     * 摆药核对
     */
    public final static WorkSpaceEnum DISPENSING_CHECK = new WorkSpaceEnum("3", "摆药核对", "5087472d7583486f96293a2faba7e882", "dispensCheck");
    /**
     * 加药核对
     */
    public final static WorkSpaceEnum DOSING_CHECK = new WorkSpaceEnum("4", "加药核对", "fec86ded9b884173aed42c6662db6c03", "dosCheck");
    /**
     * 输液中心
     */
    public final static WorkSpaceEnum INFUSION_CENTER = new WorkSpaceEnum("5","输液中心", "b7cd64384b8d4c2e965e0f464e6cfcce", "infusionCenter");
    /**
     * 静配中心
     */
    public final static WorkSpaceEnum STATIC_DRUG_CENTER = new WorkSpaceEnum("6","静配中心", "007d4d1bc06044b8a980336067cf4117", "staticDrugCenter");
    /**
     *  输液完成
     */
    public final static WorkSpaceEnum INFUSION_COMPLETED = new WorkSpaceEnum("7","输液完成","e99b3a54c42f48c0a39f07e03ab77b89","InfusionCompleted");


    private WorkSpaceEnum(String enumValue, String enumName, String nodeId, String nodeKey){
        this.enumValue = enumValue;
        this.enumName = enumName;
        this.nodeId = nodeId;
        this.nodeKey = nodeKey;
    }

    public static WorkSpaceEnum fromValue(String enumValue){
//        if (enumMap.get(enumValue)==null) {
        putSourceEnum();
//        }
        return ENUM_MAP.get(enumValue);
    }

    public static WorkSpaceEnum fromTaskNode(String taskNodeId){
//        if (enumMap.get(enumValue)==null) {
        putTaskNodeSourceEnum();
//        }
        return ENUM_MAP.get(taskNodeId);
    }

    public static void putTaskNodeSourceEnum(){

        Class clazz = WorkSpaceEnum.class;
        Field[] fields = clazz.getDeclaredFields();
        WorkSpaceEnum enumClass = null;
        for(Field field : fields) {
            if(field.getType().equals(clazz)) {
                try {
                    field.setAccessible(true);
                    enumClass = (WorkSpaceEnum)field.get(null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if(enumClass != null) {
                    ENUM_MAP.put(enumClass.getNodeId(),enumClass);
                }
            }
        }
    }
    public static void putSourceEnum(){

        Class clazz = WorkSpaceEnum.class;
        Field[] fields = clazz.getDeclaredFields();
        WorkSpaceEnum enumClass = null;
        for(Field field : fields) {
            if(field.getType().equals(clazz)) {
                try {
                    field.setAccessible(true);
                    enumClass = (WorkSpaceEnum)field.get(null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if(enumClass != null) {
                    ENUM_MAP.put(enumClass.getEnumValue(),enumClass);
                }
            }
        }
    }

    public String getEnumValue() {
        return enumValue;
    }

    public String getEnumName() {
        return enumName;
    }

    public String getNodeId() {
        return nodeId;
    }

    public String getNodeKey() {
        return nodeKey;
    }
}
